import React, {Component} from "react";
import { FormattedMessage, injectIntl } from 'react-intl';
import BeeGrid from "bee-complex-grid";
import Icon from "bee-icon";
// import Table from "bee-table";
import dragColumn from "tinper-bee/lib/dragColumn.js";
import sum from "tinper-bee/lib/sum.js";
import { Table, Checkbox, Pagination} from 'tinper-bee';
import multiSelect from "tinper-bee/lib/multiSelect.js";
const SumTable = sum(Table);
const MultiSelectTable = multiSelect(SumTable, Checkbox);
const DragColumnTable = dragColumn(Table);
import './index.less'
// import BigData from "bee-table/bulid/lib/bigData.js";
// const BigDataTable = BigData(Table);
//<FormattedMessage id="js.Ref.Ref224.0014" defaultMessage="暂无数据"/>
const NoData = () => {
    return (
      <p className="no-data">
          <Icon type="uf-list-s-o"/>
          <p>暂无数据</p>
      </p>
    )
}

const defualtPaginationParam = {
    dataNumSelect: ["5","10", "50", "100", "200", "500"],
    horizontalPosition: 'center',
    verticalPosition: "bottom",
    dataNum: 2,
    btnType: {
        shape: 'border'
    },
    noBorder: true,
    confirmBtn: () => null
};
const defaultProps = {
    //   hideBodyScroll: true,
    headerScroll: false,
    bordered: false,
    data: []
};


class Grid extends Component {
    constructor(props) {
        super(props);
    }

    /**
     *获取保存的column和table上的属性
     *
     */
    getColumnsAndTablePros = () => {
        return this.grid.getColumnsAndTablePros();
    };
    /**
     *
     * 重置grid的columns
     */
    resetColumns = newColumns => {
        this.grid.resetColumns(newColumns);
    };

    exportExcel = () => {
        this.grid.exportExcel();
    };
    sortFun = (sortParam)=>{
        console.info(sortParam);
        //将参数传递给后端排序
    }

    render() {
        const { paginationObj, data, exportData,BigDataTable,columns,  ...otherProps } = this.props;
        let _paginationObj = 'none';
        if(paginationObj !== 'none') {
            paginationObj.size = paginationObj.size || 10;
            let size = paginationObj.size.toString();
            defualtPaginationParam.dataNum = defualtPaginationParam.dataNumSelect.indexOf(size || "10");
            _paginationObj = {...defualtPaginationParam, ...paginationObj};
            _paginationObj.disabled = paginationObj.disabled !== undefined
                ? paginationObj.disabled
                : data.length === 0;
        }
        const { activePage, onDataNumSelect, freshData, total, items } = paginationObj;
        let sortObj = {
            mode:'multiple',
            sortFun:this.sortFun
          }
        
        let _exportData = exportData || data;

        if(BigDataTable) {
            return (
                <div className='demo1-grid-wrapper'>
                      <MultiSelectTable 
                        className="ucf-example-grid"
                        {...otherProps}
                        syncHover={false}
                        exportData={_exportData}
                        sort={sortObj}
                        sortFun={this.sortFun}
                        // paginationObj={_paginationObj}
                        ref={el => this.grid = el}
                        emptyText={NoData}
                        columns = {columns}
                        dragborder = {true}
                        // defaultExpandAllRows={true}
                        defaultExpandedRowKeys={[1,2,3,4,5,6,7,8,9]}
                        data={data} />
                        <div className='page_wrap' style={{margin:'0 auto',width:'800px'}}>
                            <Pagination
                                first
                                last
                                prev
                                next
                                maxButtons={5}
                                boundaryLinks
                                activePage={activePage}
                                onSelect={freshData}
                                onDataNumSelect={onDataNumSelect}
                                showJump={true}
                                noBorder={true}
                                total={total}
                                items={items}
                                dataNumSelect={['5','10','50','100','200','500']}
                                />
                        </div>
                </div>
          )
        }else {
            return (
                <div className='demo1-grid-wrapper'>
                    <BeeGrid
                        className="ucf-example-grid"
                        data={data}
                        {...otherProps}
                        columns = {columns}
                        syncHover={false}
                        exportData={_exportData}
                        sort={sortObj}
                        sortFun={this.sortFun}
                        paginationObj={_paginationObj}
                        ref={el => this.grid = el}
                        emptyText={NoData}
                    />
                </div>
            );
        }
        
    }
}

Grid.defaultProps = defaultProps;
export default Grid;
